package com.example.demo.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.model.AjaxResult;
import com.example.demo.model.DefenseGroupDto;
import com.example.demo.model.StudentSubjectTeacherDto;
import com.example.demo.service.IDefenseGroupService;
import com.example.demo.service.IStudentSubjectTeacherService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/demo")
@Tag(name = "学习", description = "用于学习springboot3+mybatis-plus+swagger3")
public class DemoController {
    @Autowired
    IDefenseGroupService defenseGroupService;
    @Autowired
    IStudentSubjectTeacherService studentSubjectTeacherService;


    @GetMapping("/helloWord")
    @Operation(summary = "HelloWorld", description = "打个招呼！")
    public AjaxResult helloWord() {
        return AjaxResult.success("Hello Word!");
    }

    @GetMapping("/getDefenseGroupById")
    @Operation(summary = "根据ID获取答辩组信息", description = "根据答辩组ID查询答辩组的详细信息")
    public AjaxResult getDefenseGroupById(@Parameter Long defenseGroupId) {
        DefenseGroupDto defenseGroupDto = defenseGroupService.getDefenseGroupById(defenseGroupId);
        if (defenseGroupDto == null) {
            return AjaxResult.error("获取结果为空！");
        } else {
            return AjaxResult.success(defenseGroupDto);
        }

    }


    @PostMapping("/getStudentSubjectTeachers")
    @Operation(summary = "师生双选列表--不分页", description = "根据筛选条件查询学生-课题-教师关系列表")
    public AjaxResult getStudentSubjectTeachers(@RequestBody StudentSubjectTeacherDto requ) {
        List<StudentSubjectTeacherDto> studentSubjectTeacherDtos = studentSubjectTeacherService.getStudentSubjectTeachers(requ);
        if (studentSubjectTeacherDtos == null || studentSubjectTeacherDtos.isEmpty()) {
            return AjaxResult.error("获取结果为空！");
        } else {
            return AjaxResult.success(studentSubjectTeacherDtos);
        }
    }


    @PostMapping("/getStudentSubjectTeachersByPage")
    @Operation(summary = "师生双选列表--mybatisPlus分页", description = "根据筛选条件查询学生-课题-教师关系列表")
    public AjaxResult getStudentSubjectTeachersByPage(@RequestBody StudentSubjectTeacherDto requ) {
        Page<StudentSubjectTeacherDto> studentSubjectTeacherDtos = studentSubjectTeacherService.getStudentSubjectTeachersByPage(requ);
        if (studentSubjectTeacherDtos == null) {
            return AjaxResult.error("获取结果为空！");
        } else {
            return AjaxResult.success(studentSubjectTeacherDtos);
        }
    }


    @PostMapping("/addDefenseGroup")
    @Operation(summary = "新增答辩组", description = "新增答辩组--事务")
    public AjaxResult addDefenseGroup(@RequestBody DefenseGroupDto requ) {
        if (defenseGroupService.addDefenseGroup(requ)) {
            return AjaxResult.success("添加成功！");
        } else {
            return AjaxResult.error("添加失败！");
        }
    }

    @PostMapping("/deleteDefenseGroup")
    @Operation(summary = "删除答辩组", description = "删除答辩组--物理删除")
    public AjaxResult deleteDefenseGroup(@Parameter(description = "答辩组编号", required = true) Long defenseGroupId) {
        if (defenseGroupService.deleteDefenseGroup(defenseGroupId) > 0) {
            return AjaxResult.success("删除成功！");
        } else {
            return AjaxResult.error("删除失败！");
        }
    }
}
